package com.yand.controller.business.classtime;


import com.github.pagehelper.PageInfo;
import com.yand.api.entity.business.classtime.THfScheduleClass;
import com.yand.api.entity.business.custom.THfStudent;
import com.yand.api.entity.common.Result;
import com.yand.api.service.business.classtime.ScheduleClassService;
import com.yand.api.service.business.custom.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 *  排课控制器类
 */
@Api(tags = "排课管理控制器类")
@RestController
@RequestMapping("scheduleclass")
public class ScheduleClassController {

    @Autowired
    private ScheduleClassService scheduleClassService;

    @Autowired
    private StudentService studentService;

    /**
     *  跳转排课管理列表
     * @param scheduleClass
     * @param model
     * @return
     */
    @ApiOperation("跳转排课列表页面")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleClass", value = "排课列表信息", required = true)
    })
    @GetMapping("/list")
    public ModelAndView list(THfScheduleClass scheduleClass, Model model){

        ModelAndView modelAndView = new  ModelAndView();
        modelAndView.setViewName("business/classtime/scheduleclass-list");
        PageInfo<THfScheduleClass> studentPageInfo = scheduleClassService.queryAllStudentList(scheduleClass);
        model.addAttribute("pageInfo",studentPageInfo);
        model.addAttribute("scheduleClass",scheduleClass);

        return modelAndView;
    }

    @ApiOperation("排课信息添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleClass", value = "排课列表信息", required = true)
    })
    @GetMapping("/class")
    public ModelAndView list(THfStudent student, Model model){
        ModelAndView modelAndView = new  ModelAndView();

        modelAndView.setViewName("business/classtime/schedulestudent-list");
        PageInfo<THfStudent> studentPageInfo = studentService.queryAllStudentList(student);
        model.addAttribute("pageInfo",studentPageInfo);

        model.addAttribute("student",student);

        return modelAndView;
    }


    /**
     * 逻辑
     *
     * @param studentIds
     * @return
     */
    @ApiOperation("跳转到排课页面")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleClass", value = "添加排课计划", required = true)
    })
    @GetMapping("/attendClass/plan/{studentIds}")
    public ModelAndView attendClassPage(@PathVariable(value = "studentIds") String studentIds, Model model){

        String studentNames = studentService.getStudentName(studentIds);

        ModelAndView modelAndView = new  ModelAndView();

        modelAndView.setViewName("business/classtime/scheduleclass-add");
        model.addAttribute("studentName", studentNames);
        model.addAttribute("studentIds", studentIds);
        return modelAndView;
    }



    @ApiOperation("添加排课计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleClass", value = "添加排课计划", required = true)
    })
    @PostMapping("/attendClass/plan")
    public Result attendClass(THfScheduleClass scheduleClass){
        scheduleClassService.insertScheduleClass(scheduleClass);

        return new Result(0);
    }


    /**
     * 判断当前选择的课程的合理性
     *  1，判断该学生是否已经安排了上课计划，
     *  2，如果有则 判断，当选择的时间， 均在 库里的开始时间之前， 或则均在库里的结束之间之后，则允许
     *  3，否则不允许
     * @param studentIds
     * @param date
     * @param timeLimit
     * @return
     */
    @ApiOperation("判断排课是否合理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleClass", value = "判断排课是否合理", required = true)
    })
    @PostMapping("/attendClass/check")
    public Result checkAttentClass(String studentIds, String date, String timeLimit){

        return scheduleClassService.checkClassPlan(studentIds, date, timeLimit);
    }

    /**
     * 排课计划删除
     * @param date
     * @param timeLimit
     * @param teacherId
     * @return
     */
    @ApiOperation("删除排课计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleClass", value = "删除排课计划", required = true)
    })
    @PostMapping("/attendClass/delete")
    public Result deleteClass(String date, String timeLimit, String teacherId){
        scheduleClassService.deleteClass(date, timeLimit, teacherId);
        return new Result(0);
    }

    /**
     * 跳转上课确认页面
     * @param scheduleClass
     * @param model
     * @return
     */
    @ApiOperation("已上课确认页面")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleClass", value = "已上课确认计划", required = true)
    })
    @GetMapping("/attendClass/sure/list")
    public ModelAndView sureClass(THfScheduleClass scheduleClass, Model model){

        ModelAndView modelAndView = new  ModelAndView();
        modelAndView.setViewName("business/classtime/scheduleclass-sure-list");
        scheduleClass.setStatus(1);
        PageInfo<THfScheduleClass> studentPageInfo = scheduleClassService.queryAllStudentList(scheduleClass);
        model.addAttribute("pageInfo",studentPageInfo);
        model.addAttribute("scheduleClass",scheduleClass);
        return modelAndView;
    }

    /**
     * 跳转上课确认页面
     * @param scheduleClassId
     * @param
     * @return
     */
    @ApiOperation("已上课确认页面")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scheduleClass", value = "已上课确认计划", required = true)
    })
    @PostMapping("/attendClass/sure/{scheduleClassId}")
    public Result sureClass(@PathVariable(value = "scheduleClassId") String scheduleClassId){


        return scheduleClassService.sureAttendClass(scheduleClassId);
    }















}
